from django.shortcuts import HttpResponse
import json
from service.rag_neo4j_service import RagNeo4jService
from agent.chat_agent import create_agent


# 聊天
def chat(request):
    if request.method == "GET":
        # 获取用户发送的问题
        question = request.GET.get("question")
        print(f"question={question}")
        try:
            # 创建智能体
            answer = create_agent(question)
            # 设置响应数据数据格式
            data = {"code": 200, "msg": "success", "data": answer}
            return HttpResponse(json.dumps(data))
        except Exception as e:
            print(e)
            data = {"code": 200, "msg": "服务器错误", "data": "我不知道答案"}
            return HttpResponse(json.dumps(data))
